package yns.springboot.guide.demo.aop;

import java.util.Arrays;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

// 通用Aop类

@Aspect
@Component
public class LogAspect {
	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Before("execution(* yns.springboot.guide.demo.controller..*.*(..))")
	public void logBefore() {
		logger.info("LogAspect logBefore method");
	}

	@After("execution(* yns.springboot.guide.demo.controller..*.*(..))")
	public void logAfter(JoinPoint joinPoint) {
		logger.info("LogAspect logAfter : TargetClass=" + joinPoint.getTarget().getClass() + ",Method=" + joinPoint.getSignature()
				+ ",Args=" + Arrays.asList(joinPoint.getArgs()));
	}
}
